<template>
  <div class="home">
    <header>
      <div class="home1">
        <img src="../img/1.png" alt />
      </div>
      <div class="search">
        <p @click="tocity" class="citysize">{{city}}</p>
        <input type="text" placeholder="请在这里输入区域/商圈" />
      </div>
    </header>
    <main>
      <div class="swiper">
        <van-swipe class="my-swipe" :autoplay="2000" indicator-color="white">
          <van-swipe-item>
            <img src="../img/swiper.png" alt />
          </van-swipe-item>
          <van-swipe-item>
            <img src="../img/swiper2.jpg" alt />
          </van-swipe-item>
          <van-swipe-item>
            <img src="../img/swiper3.jpg" alt />
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="box">
        <a @click="go1">
          <img src="../img/01.png" alt />
          <span>买房</span>
        </a>
        <a @click="go2">
          <img src="../img/02.png" alt />
          <span>租房</span>
        </a>
        <a @click="go3">
          <img src="../img/03.png" alt />
          <span>求组</span>
        </a>
        <a @click="go4">
          <img src="../img/04.png" alt />
          <span>求购</span>
        </a>
        <a @click="go5">
          <img src="../img/05.png" alt />
          <span>地图找房</span>
        </a>
        <a @click="go6">
          <img src="../img/06.png" alt />
          <span>资讯</span>
        </a>
        <a @click="go7">
          <img src="../img/07.png" alt />
          <span>楼市圈</span>
        </a>
        <a @click="go8">
          <img src="../img/08.png" alt />
          <span>经纪人</span>
        </a>
        <a @click="go9">
          <img src="../img/09.png" alt />
          <span>团购看房</span>
        </a>
        <a @click="go10">
          <img src="../img/10.png" alt />
          <span>直播看房</span>
        </a>
      </div>
      <div class="mes">
        <p>
          <b>楼市资讯</b>
          <span @click="homezx">更多</span>
        </p>
        <div class="boc">
          <div v-for="(item,index) in list" :key="index">
            <div class="boc_item">
              <span>TOP{{item.id}}</span>
              <p>{{item.title}}</p>
            </div>
          </div>
        </div>
      </div>
      <div class="house">
        <p>
          <b>热门楼盘</b>
          <span @click="redoor">更多</span>
        </p>
        <div class="redoor">
          <div v-for="(item,index) in list" :key="index" class="redoor_xuan" @click="detail(item)">
            <img src="../img/home.png" alt />
            <div class="redoor_item">
              <h4>{{item.title}}</h4>
              <p>43平/2室 1厅/远洋新天地</p>
              <span>{{item.price}}万</span>
              <p class="style">小区</p>
            </div>
          </div>
        </div>
      </div>
      <div class="people">
        <p>
          <b>经纪人</b>
          <span @click="jingjiren">更多</span>
        </p>
        <div class="people_scroll">
          <a v-for="(item,index) in list" :key="index">
            <div class="box">
              <img :src="item.img" alt />
              <p>{{item.title}}</p>
              <span>建发·文翰府</span>
              <div class="zi">
                <van-icon name="chat-o" />
                <span>咨询</span>
              </div>
            </div>
          </a>
        </div>
        <div class="img">
          <img src="../img/预售.png" alt />
        </div>
      </div>
      <div class="twohand">
        <p>
          <b>二手房</b>
          <span @click="twomore">更多</span>
        </p>
        <div class="redoor">
          <div v-for="(item,index) in list" :key="index" class="redoor_xuan" @click="detail(item)">
            <img src="../img/home.png" alt />
            <div class="redoor_item">
              <h4>{{item.title}}</h4>
              <p>43平/2室 1厅/远洋新天地</p>
              <span>{{item.price}}万</span>
              <p class="style">小区</p>
            </div>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      list: [],
      city: ""
    };
  },
  created() {
    this.getList();
    this.city = localStorage.getItem("city") || "北京";
  },
  methods: {
    //详情
    detail(item) {
      this.$router.push(`/detail/${item.id}`);
      // this.$router.push({
      //   name:"Detail",
      //   params:item.id,
      // })
    },

    go1() {
      this.$router.push("/twomore");
    },
    go2() {
      this.$router.push("/zu");
    },
    go3() {
      this.$router.push("/qiuzu");
    },
    go4() {
      this.$router.push("/qiugou");
    },
    go5() {
      this.$router.push("/map");
    },
    go6() {
      this.$router.push("/zixun");
    },
    go7() {
      this.$router.push("/loushi");
    },
    go8() {
      this.$router.push("/people");
    },
    go9() {
      this.$router.push("/tuangou");
    },
    go10() {
      this.$router.push("/zhibo");
    },
    //获取数据
    getList() {
      axios({
        url: "/api/getList",
        method: "post"
      }).then(res => {
        // console.log(res);
        this.list = res.data.data;
      });
    },
    twomore() {
      this.$router.push("/twomore");
    },
    redoor() {
      this.$router.push("/buy");
    },
    homezx() {
      this.$router.push("/zixun");
    },
    jingjiren() {
      this.$router.push("/people");
    },
    tocity() {
      this.$router.push("/city");
    }
  }
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
header {
  width: 100%;
  height: 100px;
  align-items: center;
  border-bottom: 1px solid #ccc;
  background: rgb(41, 158, 204);
  .home1 {
    height: 50px;
  }
  .search {
    width: 90%;
    height: 30px;
    border-radius: 10px;
    background: #f1f1f1;
    display: flex;
    align-items: center;
    padding: 0 10px;
    margin: 10px 5%;
    .citysize{
      font-size: 15px;
      color: #333;
    }
    input {
      padding-left: 25px;
      border: none;
      background: #f1f1f1;
    }
  }
}
main {
  flex: 1;
  overflow-y: scroll;
  .swiper img {
    width: 100%;
    height: 200px;
  }
  .box {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    a {
      width: 20%;
      text-align: center;
      padding: 5px 0;
      img {
        width: 50px;
        height: 50px;
      }
      span {
        margin-top: 3px;
        display: block;
        align-items: center;
        color: #000;
        font-size: 12px;
      }
    }
  }
  .mes {
    width: 90%;
    margin: 0 5%;
    margin-top: 15px;
    p {
      display: flex;
      justify-content: space-between;
      span {
        font-size: 14px;
        font-weight: bold;
        color: #999;
      }
    }
    .boc {
      box-shadow: 0 0 3px 3px #f1f1f1;
      height: 180px;
      overflow-y: scroll;
      margin: 5% 0;
      .boc_item {
        display: flex;
        align-items: center;
        font-size: 14px;
        padding-left: 8px;
        span {
          color: #fff;
          background: rgb(250, 136, 172);
          padding: 1.5px;
        }
        p {
          padding-left: 20px;
          margin: 10px 0;
          overflow-y: scroll;
          color: #333;
        }
      }
    }
  }
  .house {
    width: 90%;
    margin: 0 5%;
    margin-top: 15px;
    p {
      display: flex;
      justify-content: space-between;
      span {
        font-size: 14px;
        font-weight: bold;
        color: #999;
      }
    }
    .redoor {
      height: 300px;
      overflow: hidden;
      .redoor_xuan {
        display: flex;
        padding: 10px;
        img {
          width: 120px;
          height: 80px;
        }
        .redoor_item {
          margin-left: 10px;
        }
      }
    }
  }
  .people {
    width: 90%;
    margin: 0 5%;
    margin-top: 15px;
    p {
      display: flex;
      justify-content: space-between;
      span {
        font-size: 14px;
        font-weight: bold;
        color: #999;
      }
    }
    .people_scroll {
      display: flex;
      overflow-x: scroll;
      a {
        display: block;
        height: 150px;
        text-align: center;
        align-items: center;
        box-shadow: 0 0 2px 2px #ccc;
        margin: 20px 12px;
        padding: 10px;
        .box {
          display: flex;
          justify-content: center;
          width: 100px;
          margin-top: 3px;
          img {
            width: 50px;
            height: 50px;
            border-radius: 50%;
          }
          p {
            color: #000;
            font-size: 14px;
            font-weight: bold;
            display: block;
            margin-top: 3px;
          }
          span {
            font-size: 12px;
            color: #ccc;
            display: block;
            margin-top: 3px;
          }
          .zi {
            width: 70px;
            height: 30px;
            border: 1px solid none;
            background: rgb(245, 100, 100);
            border-radius: 20px;
            display: flex;
            align-items: center;
            text-align: center;
            justify-content: space-between;
            padding: 12px;
            margin-top: 3px;
            color: #fff;
            van-icon {
              color: #fff;
            }
            span {
              color: #fff;
            }
          }
        }
      }
    }
  }
  .twohand {
    width: 90%;
    margin: 0 5%;
    margin-top: 5px;
    p {
      display: flex;
      justify-content: space-between;
      span {
        font-size: 14px;
        font-weight: bold;
        color: #999;
      }
    }
    .redoor {
      height: 300px;
      overflow: hidden;
      .redoor_xuan {
        display: flex;
        padding: 10px;
        img {
          width: 120px;
          height: 80px;
        }
        .redoor_item {
          margin-left: 10px;
        }
      }
    }
  }
}
footer {
  height: 50px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
</style>